package Homework.Top04;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Top07 {
    public static void main(String[] args) {
        Writer f = null;
        Scanner input = new Scanner(System.in);
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
        boolean flag = true;
        try {
            try {
                f = new FileWriter("D:\\zuoye01\\111.txt");
            } catch (IOException e) {
                e.printStackTrace();
            }
            while (flag) {
                System.out.println("请输入字符:");
                String num = input.nextLine();
                Date date = new Date();
                if ("结束".equals(num)) {
                    f.write(num + "\n");
                    flag = false;
                    System.out.println("退出程序!");
                } else {
                    f.write(num + "\n");
                    System.out.println(sdf.format(date) + " " + num);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (f != null) {
                    f.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

